package com.qf.hospital.mapper;

import com.qf.hospital.entity.Pharmacy;
import com.qf.hospital.entity.PharmacyExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface PharmacyMapper {
    long countByExample(PharmacyExample example);

    int deleteByExample(PharmacyExample example);

    int deleteByPrimaryKey(Integer pharmacyId);

    int insert(Pharmacy record);

    int insertSelective(Pharmacy record);

    List<Pharmacy> selectByExample(PharmacyExample example);

    Pharmacy selectByPrimaryKey(Integer pharmacyId);

    int updateByExampleSelective(@Param("record") Pharmacy record, @Param("example") PharmacyExample example);

    int updateByExample(@Param("record") Pharmacy record, @Param("example") PharmacyExample example);

    int updateByPrimaryKeySelective(Pharmacy record);

    int updateByPrimaryKey(Pharmacy record);

    /**
     * 查询药品信息
     * @param drugname
     * @return
     */
    List<Pharmacy> selectDrug(@Param("drugname") String drugname);


    /**
     * 悲观锁 加锁
     * @param id
     * @return
     */
    @Select("select * from pharmacy where id = #{id} for update")
    Pharmacy selectForUpdate(@Param("id")Integer id);


    /**
     * 乐观锁 实现修改
     * @param pharmacy
     * @return
     */
    @Update("update pharmacy set drug_store_num = drug_store_num - #{pharmacy.drugStoreNum} , version = version + 1 where id = #{pharmacy.pharmacy_id} and version = #{version}")
    int updateForHappy(@Param("pharmacy") Pharmacy pharmacy);
}